<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var customerDataGrid;
    $(function() {
        customerDataGrid = $('#customerDataGrid').datagrid({
        url : '${path}/customer/dataGrid',
        striped : true,
        rownumbers : true,
        pagination : true,
        singleSelect : true,
        idField : 'id',
        sortName : 'id',
        sortOrder : 'asc',
        pageSize : 20,
        pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500],
        frozenColumns : [ [ {
            width : '100',
            title : '客户名称',
            field : 'areaName',
            sortable : true
        },{
            width : '80',
            title : '户号',
            field : 'cusName',
            sortable : true
        },{
            width : '80',
            title : '联系人',
            field : 'userName',
            sortable : true
        },{
            width : '120',
            title : '联系方式',
            field : 'cusPhoneNum',
            sortable : true
        },{
            width : '100',
            title : '地址',
            field : 'companyAddress',
            sortable : true
        },{
            width : '90',
            title : '电能表表号',
            field : 'eleNum',
            sortable : true
        },{
            width : '60',
            title : '计量装置',
            field : 'eleMeter',
            sortable : true
        },{
            width : '60',
            title : '倍率',
            field : 'eleRate',
            sortable : true
        },  {
            width : '60',
            title : '规格',
            field : 'eleSpec',
            sortable : true
        }, {
            field : 'action2',
            title : '图片',
            width : 210,
            formatter : function(value, row, index) {
                var str = '';
                <shiro:hasPermission name="/customer/archives">
                    str += $.formatString('<a href="javascript:void(0)" class="customer-easyui-linkbutton-archives" data-options="plain:true,iconCls:\'fi-photo icon-blue\'" onclick="customerArchives(\'{0}\');" >查看档案图片</a>', row.id);
                </shiro:hasPermission>
                  <shiro:hasPermission name="/customer/upload">
                    str += $.formatString('<a href="javascript:void(0)" class="customer-easyui-linkbutton-download" data-options="plain:true,iconCls:\'fi-arrow-up icon-blue\'" onclick="customerUpload(\'{0}\');" >上传图片</a>', row.id);
                </shiro:hasPermission>
                return str;
        	}
        },{
            field : 'action',
            title : '操作',
            width : 230,
            formatter : function(value, row, index) {
                var str = '';
	            <shiro:hasPermission name="/customer/picture">
                    str += $.formatString('<a href="javascript:void(0)" class="customer-easyui-linkbutton-picture" data-options="plain:true,iconCls:\'fi-photo icon-blue\'" onclick="customerPicture(\'{0}\');" >查看运维图片</a>', row.id);
                </shiro:hasPermission>
                <shiro:hasPermission name="/customer/edit">
                    str += $.formatString('<a href="javascript:void(0)" class="customer-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="customerEditFun(\'{0}\');" >编辑</a>', row.id);
                </shiro:hasPermission>
                <shiro:hasPermission name="/customer/delete">
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="customer-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="customerDeleteFun(\'{0}\');" >删除</a>', row.id);
                </shiro:hasPermission>
                return str;
            }
        } ] ],
        onLoadSuccess:function(data){
       		$('.customer-easyui-linkbutton-archives').linkbutton({text:'查看档案图片'});
        	$('.customer-easyui-linkbutton-picture').linkbutton({text:'查看运维图片'});
        	$('.customer-easyui-linkbutton-download').linkbutton({text:'上传档案图片'});
            $('.customer-easyui-linkbutton-edit').linkbutton({text:'编辑'});
            $('.customer-easyui-linkbutton-del').linkbutton({text:'删除'});
        },
        toolbar : '#customerToolbar'
    });
});


/**
**excel导入
*/
function customerExcel() {
    parent.$.modalDialog({
        title : 'excel导入',
        width : 400,
        height : 200,
        href : '${path}/customer/uploadExcelPage',
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = customerDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#customerExcel');
                f.submit();
            }
        } ]
    });
}
/**
 * 添加框
 * @param url
 */
function customerAddFun() {
    parent.$.modalDialog({
        title : '添加',
        width : 700,
        height : 600,
        href : '${path}/customer/addPage',
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = customerDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#customerAddForm');
                f.submit();
            }
        } ]
    });
}

/**
 * 上传图片
 */
function customerUpload(id) {
    if (id == undefined) {
        var rows = customerDataGrid.datagrid('getSelections');
        id = rows[0].id;
    } else {
        customerDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
    }
    document.getElementById("hd1").value=id;
    parent.$.modalDialog({
        title : '上传图片',
        width : 400,
        height : 400,
        href :  '${path}/customer/uploadPage',
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = customerDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#customerUpload');
                f.submit();
            }
        } ]
    });
}



/**
 * 查看档案图片
 */
function customerArchives(id) {
    if (id == undefined) {
        var rows = customerDataGrid.datagrid('getSelections');
        id = rows[0].id;
    } else {
        customerDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
    }
    parent.$.modalDialog({
        title : '图片',
        width : 700,
        height : 400,
        href :  '${path}/customer/archives?cId=' + id,
        
    });
}

/**
 * 查看运维图片
 */
function customerPicture(id) {
    if (id == undefined) {
        var rows = customerDataGrid.datagrid('getSelections');
        id = rows[0].id;
    } else {
        customerDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
    }
    parent.$.modalDialog({
        title : '图片',
        width : 700,
        height :400,
        href :  '${path}/customer/picture?cId=' + id,
        
    });
}

/**
 * 编辑
 */
function customerEditFun(id) {
    if (id == undefined) {
        var rows = customerDataGrid.datagrid('getSelections');
        id = rows[0].id;
    } else {
        customerDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
    }
    parent.$.modalDialog({
        title : '编辑',
        width : 700,
        height : 400,
        href :  '${path}/customer/editPage?id=' + id,
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = customerDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#customerEditForm');
                f.submit();
            }
        } ]
    });
}


/**
 * 删除
 */
 function customerDeleteFun(id) {
     if (id == undefined) {//点击右键菜单才会触发这个
         var rows = customerDataGrid.datagrid('getSelections');
         id = rows[0].id;
     } else {//点击操作里面的删除图标会触发这个
         customerDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
     }
     parent.$.messager.confirm('询问', '您是否要删除当前用户？', function(b) {
         if (b) {
             progressLoad();
             $.post('${path}/customer/delete', {
                 id : id
             }, function(result) {
                 if (result.success) {
                     parent.$.messager.alert('提示', result.msg, 'info');
                     customerDataGrid.datagrid('reload');
                 }
                 progressClose();
             }, 'JSON');
         }
     });
}


/**
 * 清除
 */
function customerCleanFun() {
    $('#customerSearchForm input').val('');
    customerDataGrid.datagrid('load', {});
}
/**
 * 搜索
 */
function customerSearchFun() {
     customerDataGrid.datagrid('load', $.serializeObject($('#customerSearchForm')));
}
</script>

<div class="easyui-layout" data-options="fit:true,border:false">
<!--     <div data-options="region:'north',border:false" style="height: 30px; overflow: hidden;background-color: #fff">
        <form id="customerSearchForm">
            <table>
                <tr>
                    <th>名称:</th>
                    <td><input name="name" placeholder="搜索条件"/></td>
                    <td>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="customerSearchFun();">查询</a>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="customerCleanFun();">清空</a>
                    </td>
                </tr>
            </table>
        </form>
     </div> -->
 
    <div data-options="region:'center',border:false">
        <table id="customerDataGrid" data-options="fit:true,border:false"></table>
        <input type="hidden" id="hd1" value=""> 
    </div>
</div>
<div id="customerToolbar" style="display: none;">
	<a onclick="customerExcel();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-upload'">Excel客户信息导入</a>
	<a href="http://112.74.175.63:8080/Instructions.docx" >导入前请阅读指南</a>
	<a href="http://112.74.175.63:8080/template.xlsx" >点击下载Excel模板</a>
    <shiro:hasPermission name="/customer/add">
        <a onclick="customerAddFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-page-add'">添加</a>
    </shiro:hasPermission>
</div>